﻿using System;
using System.Windows.Forms;
using System.Diagnostics;

namespace GatherSafe
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            MIRsettings.Instance.Load();

            cbScanUnmounted.Checked = MIRsettings.Instance.ScanUnmounted;

            udPlayerRange.Value = (decimal)MIRsettings.Instance.PlayerRange;
            cbDCFollow.Checked = MIRsettings.Instance.DCFollow;
            udDCFollow.Value = (decimal)MIRsettings.Instance.DCFollowTime;
            cbDCTarget.Checked = MIRsettings.Instance.DCTarget;
            udDCTarget.Value = (decimal)MIRsettings.Instance.DCTargetTime;
            cbPlayerDetection.Checked = MIRsettings.Instance.PlayerDetection;
            cbNodeBlacklist.Checked = MIRsettings.Instance.NodeBlacklist;
            udMobDistance.Value = (decimal)MIRsettings.Instance.MobDistance;
            udMobCount.Value = (decimal)MIRsettings.Instance.MobCount;
            udPlayerNodeRange.Value = (decimal)MIRsettings.Instance.PlayerDistance;
            cbMobBlacklisting.Checked = MIRsettings.Instance.NodeMobBlacklist;
            cbPlayerBlacklisting.Checked = MIRsettings.Instance.NodePlayerBlacklist;
            cbTimedLogout.Checked = MIRsettings.Instance.TimedLogout;
            udLogoutTime.Value = (decimal)MIRsettings.Instance.LogoutTime;
            udClearFollowers.Value = (decimal)MIRsettings.Instance.ClearListTime;
            cbFollowNotifications.Checked = MIRsettings.Instance.FollowNotifications;
            udFollowNotificationsStartAfter.Value = (decimal)MIRsettings.Instance.FollowNotificationsTimeStartAfter;
            udFollowNotificationEveryXSeconds.Value = (decimal)MIRsettings.Instance.FollowNotificationsTime;
            cbTargetNotifications.Checked = MIRsettings.Instance.TargetNotifications;
            udTargetNotificationsStartAfter.Value = (decimal)MIRsettings.Instance.TargetNotificationsTimeStartAfter;
            udTargetNotificationsTime.Value = (decimal)MIRsettings.Instance.TargetNotificationsTime;
            cbPlayerCloseToNode.Checked = MIRsettings.Instance.PlayerCloseToNode;
            udPlayerCloseToNodeRange.Value = MIRsettings.Instance.PlayerCloseToNodeRange;

            udBlacklistTime.Value = (decimal)MIRsettings.Instance.BlacklistTime;

            ddlColors.Items.Add("MediumSlateBlue");
            ddlColors.Items.Add("Blue");
            ddlColors.Items.Add("Green");
            ddlColors.Items.Add("Red");
            ddlColors.Items.Add("Orange");
            ddlColors.Items.Add("Purple");
            ddlColors.Items.Add("White");

            int position = (int)MIRsettings.Instance.NotificationColor;  //Had issues for some reason putting this in the next line
            ddlColors.SelectedIndex = position;

            lblNotificationExample.ForeColor = ColorSelection(position);  //Set example color

            if (MIRsettings.Instance.PlayerDetection)
            {
                EnablePlayerDetection();
            }
            else
            {
                DisablePlayerDetection();
                DisableFollowNotifications();
                DisableTargetNotifications();
                DisableDCFollow();
                DisableDCTarget();
            }

            if (MIRsettings.Instance.DCFollow)
            {
                EnableDCFollow();
            }
            else
            {
                DisableDCFollow();
            }

            if (MIRsettings.Instance.DCTarget)
            {
                EnableDCTarget();
            }
            else
            {
                DisableDCTarget();
            }

            if (MIRsettings.Instance.NodeBlacklist)
            {
                EnableNodeBlacklisting();
            }
            else
            {
                DisableNodeBlacklisting();
                DisableMobBlacklisting();
                DisablePlayerNodeBlacklisting();
            }

            if (MIRsettings.Instance.NodeMobBlacklist)
            {
                EnableMobBlacklisting();
            }
            else
            {
                DisableMobBlacklisting();
            }

            if (MIRsettings.Instance.NodePlayerBlacklist)
            {
                EnablePlayerNodeBlacklisting();
            }
            else
            {
                DisablePlayerNodeBlacklisting();
            }

            if (MIRsettings.Instance.TimedLogout)
            {
                EnableTimedLogout();
            }
            else
            {
                DisableTimedLogout();
            }

            if (MIRsettings.Instance.FollowNotifications)
            {
                EnableFollowNotifications();
            }
            else
            {
                DisableFollowNotifications();
            }

            if (MIRsettings.Instance.TargetNotifications)
            {
                EnableTargetNotifications();
            }
            else
            {
                DisableTargetNotifications();
            }


        }

        private void udPlayerRange_ValueChanged(object sender, EventArgs e)
        {
            MIRsettings.Instance.PlayerRange = (int) udPlayerRange.Value;
            MIRsettings.Instance.Save();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            MIRsettings.Instance.Save();
            this.Close();
        }

        private void udMobDistance_ValueChanged(object sender, EventArgs e)
        {
            MIRsettings.Instance.MobDistance = (int)udMobDistance.Value;
            MIRsettings.Instance.Save();
        }

        private void cbPlayerBlacklist_CheckedChanged(object sender, EventArgs e)
        {
            MIRsettings.Instance.PlayerDetection = (bool)cbPlayerDetection.Checked;
            MIRsettings.Instance.Save();

            if (cbPlayerDetection.Checked)
            {
                EnablePlayerDetection();
            } 
            else 
            {
                DisablePlayerDetection();
            }

        }

        private void cbNodeBlacklist_CheckedChanged(object sender, EventArgs e)
        {
            MIRsettings.Instance.NodeBlacklist = (bool)cbNodeBlacklist.Checked;
            MIRsettings.Instance.Save();

            if (cbNodeBlacklist.Checked)
            {
                EnableNodeBlacklisting();
            }
            else
            {
                DisableNodeBlacklisting();
            }


        }

        private void udPlayerNodeRange_ValueChanged(object sender, EventArgs e)
        {
            MIRsettings.Instance.PlayerDistance = (int)udPlayerNodeRange.Value;
            MIRsettings.Instance.Save();
        }

        private void udMobCount_ValueChanged(object sender, EventArgs e)
        {
            MIRsettings.Instance.MobCount = (int)udMobCount.Value;
            MIRsettings.Instance.Save();
        }

        private void cbDCTarget_CheckedChanged(object sender, EventArgs e)
        {
            MIRsettings.Instance.DCTarget = (bool)cbDCTarget.Checked;
            MIRsettings.Instance.Save();

            if (cbDCTarget.Checked)
            {
                EnableDCTarget();
            }
            else
            {
                DisableDCTarget();
            }

        }

        private void cbDCFollow_CheckedChanged(object sender, EventArgs e)
        {
            MIRsettings.Instance.DCFollow = (bool)cbDCFollow.Checked;
            MIRsettings.Instance.Save();

            if (cbDCFollow.Checked)
            {
                EnableDCFollow();
            }
            else
            {
                DisableDCFollow();
            }
        }

        private void udDCTarget_ValueChanged(object sender, EventArgs e)
        {
            MIRsettings.Instance.DCTargetTime = (int)udDCTarget.Value;
            MIRsettings.Instance.Save();
        }

        private void udDCFollow_ValueChanged(object sender, EventArgs e)
        {
            MIRsettings.Instance.DCFollowTime = (int)udDCFollow.Value;
            MIRsettings.Instance.Save();
        }

        private void cbMobBlaclisting_CheckedChanged(object sender, EventArgs e)
        {
            MIRsettings.Instance.NodeMobBlacklist = (bool)cbMobBlacklisting.Checked;
            MIRsettings.Instance.Save();

            if (cbMobBlacklisting.Checked)
            {
                EnableMobBlacklisting();
            }
            else
            {
                DisableMobBlacklisting();
            }
        }

        private void cbPlayerBlacklisting_CheckedChanged(object sender, EventArgs e)
        {
            MIRsettings.Instance.NodePlayerBlacklist = (bool)cbPlayerBlacklisting.Checked;
            MIRsettings.Instance.Save();

            if (cbPlayerBlacklisting.Checked)
            {
                EnablePlayerNodeBlacklisting();
            }
            else
            {
                DisablePlayerNodeBlacklisting();
            }

        }

        private void DisablePlayerDetection()
        {
            udPlayerRange.Enabled = false;
            cbDCTarget.Enabled = false;
            udDCTarget.Enabled = false;
            cbDCFollow.Enabled = false;
            udDCFollow.Enabled = false;
            udClearFollowers.Enabled = false;
            cbFollowNotifications.Enabled = false;
            udFollowNotificationsStartAfter.Enabled = false;
            udTargetNotificationsStartAfter.Enabled = false;
            udFollowNotificationEveryXSeconds.Enabled = false;
            cbTargetNotifications.Enabled = false;
            udTargetNotificationsStartAfter.Enabled = false;
            udTargetNotificationsTime.Enabled = false;
        }

        private void EnablePlayerDetection()
        {
            udPlayerRange.Enabled = true;
            cbDCTarget.Enabled = true;
            udDCTarget.Enabled = true;
            cbDCFollow.Enabled = true;
            udDCFollow.Enabled = true;
            udClearFollowers.Enabled = true;
            cbFollowNotifications.Enabled = true;
            udFollowNotificationEveryXSeconds.Enabled = true;
            cbTargetNotifications.Enabled = true;
            udTargetNotificationsTime.Enabled = true;
            udFollowNotificationsStartAfter.Enabled = true;
            udTargetNotificationsStartAfter.Enabled = true;
        }

        private void DisableDCTarget()
        {
            udDCTarget.Enabled = false;
        }

        private void EnableDCTarget()
        {
            udDCTarget.Enabled = true;
        }

        private void DisableDCFollow()
        {
            udDCFollow.Enabled = false;
        }

        private void EnableDCFollow()
        {
            udDCFollow.Enabled = true;
        }

        private void DisableNodeBlacklisting()
        {
            cbMobBlacklisting.Enabled = false;
            cbPlayerBlacklisting.Enabled = false;
            udMobCount.Enabled = false;
            udMobDistance.Enabled = false;
            udPlayerNodeRange.Enabled = false;
            cbPlayerCloseToNode.Enabled = false;
            udPlayerCloseToNodeRange.Enabled = false;
            udBlacklistTime.Enabled = false;
        }

        private void EnableNodeBlacklisting()
        {
            cbMobBlacklisting.Enabled = true;
            cbPlayerBlacklisting.Enabled = true;
            udMobCount.Enabled = true;
            udMobDistance.Enabled = true;
            udPlayerNodeRange.Enabled = true;
            cbPlayerCloseToNode.Enabled = true;
            udPlayerCloseToNodeRange.Enabled = true;
            udBlacklistTime.Enabled = true;
        }

        private void DisableMobBlacklisting()
        {
            udMobCount.Enabled = false;
            udMobDistance.Enabled = false;
        }

        private void EnableMobBlacklisting()
        {
            udMobCount.Enabled = true;
            udMobDistance.Enabled = true;
        }

        private void DisablePlayerNodeBlacklisting()
        {
            udPlayerNodeRange.Enabled = false;
            cbPlayerCloseToNode.Enabled = true;
            udPlayerCloseToNodeRange.Enabled = true;
        }

        private void EnablePlayerNodeBlacklisting()
        {
            udPlayerNodeRange.Enabled = true;
            cbPlayerCloseToNode.Enabled = true;
            udPlayerCloseToNodeRange.Enabled = true;
        }

        private void DisableTimedLogout()
        {
            udLogoutTime.Enabled = false;
        }

        private void EnableTimedLogout()
        {
            udLogoutTime.Enabled = true;
        }

        private void cbTimedLogout_CheckedChanged(object sender, EventArgs e)
        {
            MIRsettings.Instance.TimedLogout = (bool)cbTimedLogout.Checked;
            MIRsettings.Instance.Save();

            if (cbTimedLogout.Checked)
            {
                EnableTimedLogout();
            }
            else
            {
                DisableTimedLogout();
            }

        }

        private void udLogoutTime_ValueChanged(object sender, EventArgs e)
        {
            MIRsettings.Instance.LogoutTime = (int)udLogoutTime.Value;
            MIRsettings.Instance.Save();
        }

        private void udClearFollowers_ValueChanged(object sender, EventArgs e)
        {
            MIRsettings.Instance.ClearListTime = (int)udClearFollowers.Value;
            MIRsettings.Instance.Save();
        }

        private void udFollowNotificationEveryXSeconds_ValueChanged(object sender, EventArgs e)
        {
            MIRsettings.Instance.FollowNotificationsTime = (int)udFollowNotificationEveryXSeconds.Value;
            MIRsettings.Instance.Save();
        }

        private void udTargetNotificationsTime_ValueChanged(object sender, EventArgs e)
        {
            MIRsettings.Instance.TargetNotificationsTime = (int)udTargetNotificationsTime.Value;
            MIRsettings.Instance.Save();
        }

        private void cbTargetNotifications_CheckedChanged(object sender, EventArgs e)
        {
            MIRsettings.Instance.TargetNotifications = cbTargetNotifications.Checked;
            MIRsettings.Instance.Save();

            if (cbTargetNotifications.Checked)
            {
                EnableTargetNotifications();
            }
            else
            {
                DisableTargetNotifications();
            }

        }

        private void DisableTargetNotifications()
        {
            udTargetNotificationsTime.Enabled = false;
            udTargetNotificationsStartAfter.Enabled = false;
        }

        private void EnableTargetNotifications()
        {
            udTargetNotificationsTime.Enabled = true;
            udTargetNotificationsStartAfter.Enabled = true;
        }

        private void cbFollowNotifications_CheckedChanged(object sender, EventArgs e)
        {
            MIRsettings.Instance.FollowNotifications = cbFollowNotifications.Checked;
            MIRsettings.Instance.Save();

            if (cbFollowNotifications.Checked)
            {
                EnableFollowNotifications();
            }
            else
            {
                DisableFollowNotifications();
            }
        }

        private void DisableFollowNotifications()
        {
            udFollowNotificationEveryXSeconds.Enabled = false;
            udFollowNotificationsStartAfter.Enabled = false;
        }

        private void EnableFollowNotifications()
        {
            udFollowNotificationEveryXSeconds.Enabled = true;
            udFollowNotificationsStartAfter.Enabled = true;
        }

        private void cbPlayerCloseToNode_CheckedChanged(object sender, EventArgs e)
        {
            MIRsettings.Instance.PlayerCloseToNode = (bool)cbPlayerCloseToNode.Checked;
            MIRsettings.Instance.Save();

            if (cbPlayerCloseToNode.Checked)
            {
                EnablePlayerCloseToNode();
            }
            else
            {
                DisablePlayerCloseToNode();
            }

        }

        private void DisablePlayerCloseToNode()
        {
            udPlayerCloseToNodeRange.Enabled = false;
        }

        private void EnablePlayerCloseToNode()
        {
            udPlayerCloseToNodeRange.Enabled = true;
        }

        private void udPlayerCloseToNodeRange_ValueChanged(object sender, EventArgs e)
        {
            MIRsettings.Instance.PlayerCloseToNodeRange = (int)udPlayerCloseToNodeRange.Value;
            MIRsettings.Instance.Save();
        }

        private void udFollowNotificationsStartAfter_ValueChanged(object sender, EventArgs e)
        {
            MIRsettings.Instance.FollowNotificationsTimeStartAfter = (int)udFollowNotificationsStartAfter.Value;
            MIRsettings.Instance.Save();
        }

        private void udTargetNotificationsStartAfter_ValueChanged(object sender, EventArgs e)
        {
            MIRsettings.Instance.TargetNotificationsTimeStartAfter = (int)udTargetNotificationsStartAfter.Value;
            MIRsettings.Instance.Save();
        }

        private void ddlColors_SelectedIndexChanged(object sender, EventArgs e)
        {

            lblNotificationExample.ForeColor = ColorSelection((int)ddlColors.SelectedIndex);

            MIRsettings.Instance.NotificationColor = (int)ddlColors.SelectedIndex;
            MIRsettings.Instance.Save();
        }

        private void cbScanUnmounted_CheckedChanged(object sender, EventArgs e)
        {
            MIRsettings.Instance.ScanUnmounted = true;
            MIRsettings.Instance.Save();
        }

        private void udBlacklistTime_ValueChanged(object sender, EventArgs e)
        {
            MIRsettings.Instance.BlacklistTime = (int)udBlacklistTime.Value;
            MIRsettings.Instance.Save();
        }

        public System.Drawing.Color ColorSelection(int choice)
        {

            switch (choice)
            {
                case 0:
                    return System.Drawing.Color.MediumSlateBlue;
                case 1:
                    return System.Drawing.Color.Blue;
                case 2:
                    return System.Drawing.Color.Green;
                case 3:
                    return System.Drawing.Color.Red;
                case 4:
                    return System.Drawing.Color.Orange;
                case 5:
                    return System.Drawing.Color.Purple;
                case 6:
                    return System.Drawing.Color.White;
                default:
                    return System.Drawing.Color.MediumSlateBlue;
            }
        }
 

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            ProcessStartInfo Donate = new ProcessStartInfo("https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=tpollus%40yahoo%2ecom&lc=US&item_name=Saik&no_note=0&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHostedGuest");
            Process.Start(Donate);
        }






        


    }
}
